#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
#define MAXN 7
vector<vector<int>> g = {{0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0},
                         {0,0,0,0,0,0,0}};
vector<int> f = {0,0,0,0,0,0,0};
vector<int> isvisted = {0,0,0,0,0,0,0};
int maxn = 0;

void dfs(int current_pos,int curs)
{
    int i;
    // 当前节点走过了
    isvisted[current_pos] = 1;
    // 当前节点是否全部走过，默认为是
    bool isallv = true;
    int temp = f[current_pos];
    for(i=0;i<f[current_pos];i++){
        if( ! isvisted[g[current_pos][i]]){
            // 当前节点的第 i 个子节点没有被走过，那么可以走
            isallv = false;
            dfs(g[current_pos][i],curs+1);
        }
    }
    if(isallv){
        //当前节点的所有子节点都被走过，那么不能再走了，计算走到这儿的最大深度
        if(curs>maxn)
            maxn = curs;
    }
}

int main()
{
    int n;
    while(cin>>n){
        if(n==0) break;
        for(int i=0;i<n-1;i++){
            int a,b;
            cin>>a>>b;
            g[a][f[a]++] = b;
            g[b][f[b]++] = a;
        }
        cout<<"输出g:"<<endl;
        for(auto ii:g)
        {
            for(auto jj:ii)
            {
                cout<<jj<<" ";
            }
            cout<<"\n";
        }
        cout<<"输出f:"<<endl;
        for(auto i:f)
            cout<<i<<" ";
        dfs(1,0);
        cout<<"最短路径:"<<(n-1)*2-maxn<<endl;
    }
    return 0;
}
